package com.sdy.supermarket.mq.config;

import com.sdy.supermarket.biz.constants.MqConstants;
import com.sdy.supermarket.mq.consumer.ApporvalMessageConsumer;
import com.sdy.supermarket.mq.consumer.SupermarketMessageConsumer;
import com.sdy.mq.base.BaseMessageListener;
import com.sdy.mq.config.RocketMqConfig;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConsumerGroupConfig {
    @Autowired
    private RocketMqConfig rocketMqConfig;
    @Autowired
    private SupermarketMessageConsumer supermarketMessageConsumer;
    @Autowired
    private ApporvalMessageConsumer apporvalMessageConsumer;

    @Bean
    public DefaultMQPushConsumer demoMessageListener() throws Exception {
        return rocketMqConfig.createConsumer(new BaseMessageListener(supermarketMessageConsumer), MqConstants.Topics.TOPIC_USERCENTER);
    }

    @Bean
    public DefaultMQPushConsumer getApprovalListener() throws Exception {
        return rocketMqConfig.createConsumerGroup("getApproval-getApprovalInfo", new BaseMessageListener(apporvalMessageConsumer), MqConstants.Topics.TOPIC_APPROVAL);
    }
}
